package com.walle.ak47.commons.jaxrs.interceptor.log;

import java.util.concurrent.atomic.AtomicInteger;

import org.apache.cxf.interceptor.LoggingMessage;

import com.walle.ak47.commons.utils.DateUtils;
import com.walle.ak47.commons.utils.json.GBuilder;

public final class JsonLoggingMessage {
    public static  String ID_KEY = LoggingMessage.class.getName() + ".ID";
    private static  AtomicInteger ID = new AtomicInteger();
    
    @SuppressWarnings("unused")
	private final String heading;
    private final StringBuilder address;
    private final StringBuilder contentType;
    private final StringBuilder encoding;
    private final StringBuilder httpMethod;
    private final StringBuilder header;
    private final StringBuilder message;
    private final StringBuilder payload;
    private final StringBuilder responseCode;
    private final String id;
    private final String time ;
    

    public JsonLoggingMessage(String h, String i) {
        heading = h;
        id = i;

        contentType = new StringBuilder();
        address = new StringBuilder();
        encoding = new StringBuilder();
        httpMethod = new StringBuilder();
        header = new StringBuilder();
        message = new StringBuilder();
        payload = new StringBuilder();
        responseCode = new StringBuilder();
        time = DateUtils.timeToStr() ;
    }
    
    public String getTime()
    {
    	return this.time ;
    }
    public String getId() {
        return id;
    }
    
    public static String nextId() {
        return Integer.toString(ID.incrementAndGet());
    }
        
    
    public StringBuilder getAddress() {
        return address;
    }

    public StringBuilder getEncoding() {
        return encoding;
    }

    public StringBuilder getHeader() {
        return header;
    }
    
    public StringBuilder getHttpMethod() {
        return httpMethod;
    }

    public StringBuilder getContentType() {
        return contentType;
    }

    public StringBuilder getMessage() {
        return message;
    }

    public StringBuilder getPayload() {
        return payload;
    }

    public StringBuilder getResponseCode() {
        return responseCode;
    }

    public String toString() {
        return "\n"+GBuilder.gsonNoFormate().toJson(this)+"\n";
    }
}